import { Injectable } from "@nestjs/common";
import { AuthController } from "src/modules/auth/auth.controller";
import { MenuController } from "src/controller/menu.controller";
import { RoleController } from "src/controller/role.controller";
import { UsersController } from "src/controller/user.controller";
import { RouteDefinition } from "../descriptor/interface/message.interface";
import { DataOneDto, DataTwoDto, Message } from "../dto/action.dto";
import { ActionController } from "./action.controller";
import { DataEntity } from "src/Entity/data.entity";

@Injectable()
export class ActionService {
    private readonly messages: Message[] = [];


    // save(message): string {
    //     return `Set Hello Done ${message}`;
    // }

    // update(id: number, message: string): string {
    //     return `update ${id}:${message}`
    // }
    async getData(data: DataOneDto[] | DataTwoDto[]) {
        console.log(data);
        return data
    }


    async findAll() {
        return await DataEntity.find();
    }

    getMessage() {
        // let globafn = require("../descriptor/global/global.variable");
        // for (let i = 0; i < globafn.china.length; i++) {
        //     let message: Message = new Message();
        //     message.chineseName = globafn.china[i];
        //     message.functionName = globafn.functionName[i];
        //     this.messages.push(message);
        // }

        [
            AuthController,
            UsersController,
            RoleController,
            MenuController,
            ActionController,
        ].forEach(controller => {

            // 获取 prefix
            const prefix = Reflect.getMetadata('prefix', controller);
            // 获取 routes
            const routes: Array<RouteDefinition> = Reflect.getMetadata('routes', controller);
            routes.forEach(route => {
                let message: Message = new Message();
                message.className = prefix;
                message.chineseName = route.path;
                message.functionName = route.methodName;
                this.messages.push(message);
                // 添加 Express 路由
                // app[route.requestMethod](prefix + route.path, (req: express.Request, res: express.Response) => {
                //     instance[route.methodName](req, res);
                // });
                // console.log(prefix + route.path + route.methodName);
            });

        })

        return this.messages;
    }

}
